package com.yxtech;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by winfan on 15/8/8.
 */
public class GetReaderBody2 extends HttpServlet {


    public void init() throws ServletException {
        System.out.println("初始化 init()");
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("调用doGet方法");
        //设置响应的页面类别与页面的编码
        response.setContentType("text/html;charset=gbk");
        PrintWriter out = response.getWriter();

        out.print(request.getProtocol());
        if(request.getProtocol().endsWith("1.1")){
            out.print("<h1>谭巧芳</h1>");
        }
        for (int i = 1; i <=100 ; i++) {
            out.println("<br/>");
            for (int j = 1; j <= i; j++) {
                out.println(i+"+"+j+"="+(i+j));
            }
        }
        out.flush();
        out.close();

    }

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        BufferedReader br = request.getReader();
        String input ="";
        String body = "";
        while ((input=br.readLine())!=null){
            body +=input+"<br>";
        }
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        out.print("<html>");
        out.print("<body>");
        out.print(body);
        out.print("</body>");
        out.print("</html>");
        out.flush();
        out.close();
    }

    public void destory() {
        System.out.println("调用 destory()方法");
    }

}
